import CategoryApi from '../../api/category'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    currentPage: 1,
    size: 10000,
    categoryList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  //点击成果上传
  showPopup() {
    // 发起请求成果类型列表
    this.setData({
      show: true
    });
    this.getCategoryList()

  },
  getCategoryList() {
    wx.showLoading({
      title: "加载中..."
    })
    var that = this
    var queryInfo = {
      currentPage: that.data.currentPage,
      size: that.data.size
    }
    CategoryApi.getCategoryList(queryInfo).then(res => {
      if (res.data.code !== 200) {
        return wx.showToast({
          title: res.data.data,
          icon: 'none'
        })
      } else {
        // 更新数据
        that.setData({
          categoryList: res.data.data.records,
        })
      }
    })
    wx.hideLoading()
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  goToUpload(item) {
    var categoryInfo = item.currentTarget.dataset.category
    wx.navigateTo({
      url: '/pages/uploadachieve/index',
      success: function (res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage', {
          data: categoryInfo
        })
      }
    })
  }
})
